package com.lzb.musicplayer.adapter;

import android.graphics.Bitmap;
import android.text.TextUtils;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.lzb.basic.ProviderMultiAdapter;
import com.lzb.musicplayer.R;
import com.lzb.musicplayer.bean.GroupMusicInfo;
import com.lzb.musicplayer.bean.MusicFile;
import com.lzb.musicplayer.utils.MusicScannerUtil;

public class AlbumAdapter extends ProviderMultiAdapter<GroupMusicInfo> {

    public AlbumAdapter() {
        addItemProvider(new AlbumProvider());
    }

    private class AlbumProvider extends BaseItemProvider<GroupMusicInfo> {
        @Override
        public int getItemViewType() {
            return ProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_album;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, GroupMusicInfo bean) {
            if (bean.getList() != null && bean.getList().size() > 0) {
                MusicFile musicFile = bean.getList().get(0);
                Bitmap bit = MusicScannerUtil.getAlbumArt(getContext(), musicFile.getAlbumCover());
                baseViewHolder.setImageResource(R.id.ivAlbumItemImg, R.drawable.zhuanji);
                if (bit != null) {
                    baseViewHolder.setImageBitmap(R.id.ivAlbumItemImg, bit);
                }
                if (!TextUtils.isEmpty(bean.getList().get(0).getAlbum())) {
                    baseViewHolder.setText(R.id.tvAlbumItemName, bean.getList().get(0).getAlbum());
                }
                if (!TextUtils.isEmpty(bean.getList().get(0).getArtist())) {
                    baseViewHolder.setText(R.id.tvAlbumItemArtist, bean.getList().get(0).getArtist() + " | ");
                }
                baseViewHolder.setText(R.id.tvAlbumItemSize, bean.getList().size() + getContext().getString(R.string.music));
            }
        }
    }
}